# -*- coding: utf-8 -*-
# @Time    : 2024/10/8 下午7:50
# @Author  : zhh

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import json
import os

import pytest

from selenium import webdriver
driver = None

@pytest.fixture(scope='session', autouse=True)
def drivers(request):
    global driver
    if driver is None:
        driver = browser_initial()
        with open(r'D:\python\fmselenium\static\feishu_cookie.txt', 'r', encoding='utf8') as f:
            listCookies = json.loads(f.read())

        # 往browser里添加cookies
        for cookie in listCookies:
            cookie_dict = {
                'domain': '.feishu.cn',
                'name': cookie.get('name'),
                'value': cookie.get('value'),
                "expires": '',
                'path': '/',
                'httpOnly': False,
                'sameSite': 'None',
                'Secure': True
            }
            driver.add_cookie(cookie_dict)
        driver.get("https://140lslchw.feishu.cn/admin/index")
        # 窗口变大
        # driver.maximize_window()
        print("调用drivers ***************************************************")

    def fn():
        driver.quit()

    request.addfinalizer(fn)
    return driver


 #刷新网页
def browser_initial():
        os.chdir(r'/')
        driver = webdriver.Chrome()
        driver.get("https://140lslchw.feishu.cn/admin/index")
        return driver
